package com.zhhs.galaxyott.httpVolley.parser;

import org.json.JSONException;
import org.json.JSONObject;

import android.text.TextUtils;
import android.util.Log;

import com.zhhs.galaxyott.httpVolley.response.SingleSpeciaResponse;

/**
 * 单专题解析器
 * 
 * 
 */
public class SingleSpecialParser extends BaseParser<SingleSpeciaResponse> {

    @Override
    public SingleSpeciaResponse parse(String jsonString) {
        SingleSpeciaResponse response = new SingleSpeciaResponse();

        try {
            // 如果用fastobjson就是此处不同
            // JSONObject obj = JSON.parseObject(paramString);
            JSONObject obj = new JSONObject(jsonString);
            parseMsg(obj, response);

            // 先判断返回码.
            int errCode = obj.getInt("errCode");
            response.errCode = errCode;
            String returnCode = String.valueOf(errCode);

            if (TextUtils.isEmpty(returnCode)) {
                return null;
            }
            Log.i("DEBUG_LC", "THIS IS returnCode != 0");
            if (returnCode.equals("0")) {// 返回正常.
                JSONObject jo = obj.getJSONObject("special");
                response.bean.setSpecialId(jo.optInt("specialId"));
                response.bean.setSpecialTitle(jo.optString("specialTitle"));
                response.bean.setSpecialType(jo.optInt("specialType"));
                response.bean.setSpecialSort(jo.optInt("specialSort"));
                response.bean.setImageUrl(jo.optString("imageUrl"));

            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return response;
    }
}
